import { AppStateService } from './../../app.chef.component';
import { HomePageService } from './../chefHome/index';
import { NavigateManage } from './../../common/navigateManage';
import { GrowlMessageType } from './../../components/messageBox/growMeaageType';
import { MessageBoxService } from './../../components/messageBox/messageBoxService';
import { LocalstorageDataManage } from './../../common/localstoreage/localstoreageDataManage';
import { FrontStoreStocksService } from './../../services/frontStoreStocksService';
import { Component, OnInit } from '@angular/core';
import * as R from "ramda";

@Component({
    selector: 'chef-display',
    templateUrl: './chefDisplay.component.html',
    styleUrls: ['./chefDisplay.component.scss']
})

export class ChefDisplayComponent implements OnInit {
    constructor(private frontStoreStocksSvr: FrontStoreStocksService,private appStateService:AppStateService) { }

    private solutions;
    private selectedSolutionId;
    async  ngOnInit() {
        this.selectedSolutionId = LocalstorageDataManage.current.getValidSolution().id;
        this.solutions = await this.frontStoreStocksSvr.getChefKitchenSolutions();
    }

    save() {
        const solution = this.solutions.find(x => x.id == this.selectedSolutionId) ;
        if (!solution || !solution.id) {
            MessageBoxService.current.Growl(GrowlMessageType.Warning,'请选择显示方案');
            return false;
        }
        LocalstorageDataManage.current.setValidSolution(R.pick(["id","name"])(solution));
        this.appStateService.changeTitle(R.prop("name")(solution));
        this.frontStoreStocksSvr.empty();
        this.frontStoreStocksSvr.changeInitParseUrlOptionId(solution.id);
        NavigateManage.current.navigate(HomePageService.current.getPathByComponentName("home"));
    }

    changeSolution(target){
        this.selectedSolutionId = target.value;
    }
}